
// Source File Name:   LISTAdapterCommonImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, INTImpl, NullFlavorImpl

public abstract class LISTAdapterCommonImpl extends ANYImpl
{

    public static final String RCS_ID = "$Header: LISTAdapterCommonImpl.java 1.0 2006/07/13 15:04:39 pkiran noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: LISTAdapterCommonImpl.java 1.0 2006/07/13 15:04:39 pkiran noship $", "com.sunwayhorizo.health.hl7.datatypes.common");
    protected List mList;

    protected LISTAdapterCommonImpl(List list)
    {
        mList = new ArrayList();
        if(list == null || !verifyList(list))
        {
            if(list == null)
                throw ANYImpl.newNullException("LIST", "constructor", "list");
            verifyList(list);
        }
        mList.addAll(list);
    }

    protected LISTAdapterCommonImpl(CS cs)
    {
        super(true, cs);
        mList = new ArrayList();
        mList = null;
    }

    protected LISTAdapterCommonImpl()
    {
        mList = new ArrayList();
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return BLImpl.valueOf(mList.isEmpty());
    }

    public BL notEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return isEmpty().not();
    }

    public INT length()
    {
        if(isNull().isTrue())
            return INTImpl.nullINT(NullFlavorImpl.NI);
        else
            return INTImpl.valueOf(mList.size());
    }

    public List toList()
    {
        if(isNull().isTrue())
            return null;
        else
            return Collections.unmodifiableList(mList);
    }

    protected abstract boolean verifyItem(Object obj);

    protected boolean verifyList(List list)
    {
        boolean flag = true;
        for(Iterator iterator = list.iterator(); flag && iterator.hasNext(); flag = verifyItem(iterator.next()));
        return flag;
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        int i = 0;
//        try
//        {
//            Vector vector = new Vector();
//            for(Iterator iterator = toList().iterator(); iterator != null && iterator.hasNext();)
//            {
//                Object obj = iterator.next();
//                if((obj instanceof ANYImpl) && ((ANYImpl)obj).isNull().isFalse())
//                {
//                    i++;
//                    vector.add(((ANYImpl)obj).writeXML(xmldocument, s)[0]);
//                }
//            }
//
//            return (XMLNode[])vector.toArray(new XMLNode[i]);
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

}
